

//
//  B_ActivityDetailFooterViewTwo.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/9/27.
//  Copyright © 2018 薛小刚. All rights reserved.
//

#import "B_ActivityDetailFooterViewTwo.h"
#import "B_ReleaseImageCVC.h"

@implementation B_ActivityDetailFooterViewTwo


+(instancetype) initB_ActivityDetailFooterViewTwo {
    B_ActivityDetailFooterViewTwo * footer = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
    [footer setView];
    return footer;
}

- (void) setView {
    [self.B_collection registerNib:[UINib nibWithNibName:@"B_ReleaseImageCVC" bundle:nil] forCellWithReuseIdentifier:@"B_ReleaseImageCVC"];
}


- (void)setImageArray:(NSArray *)imageArray {
    _imageArray = imageArray;
    //    [self.B_CollectionView registerNib:[UINib nibWithNibName:@"B_ReleaseImageCVC" bundle:nil] forCellWithReuseIdentifier:@"B_ReleaseImageCVC"];
    NSInteger lines = imageArray.count % 3 == 0 ? imageArray.count / 3 : (imageArray.count / 3 + 1);
    [self.B_collection mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(((SCREEN_WIDTH - 6) / 3. + 2) * lines));
    }];
    [self.B_collection reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    B_ReleaseImageCVC * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"B_ReleaseImageCVC" forIndexPath:indexPath];
    cell.B_deleteButton.hidden = YES;
    if ([self.imageArray[indexPath.row] isKindOfClass:[NSString class]]) {
        [cell.B_ImageView sd_setImageWithURL:[NSURL URLWithString:self.imageArray[indexPath.row]]];
    } else {
        cell.B_ImageView.image = self.imageArray[indexPath.row];
    }
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.imageArray.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.collectionTapAction) {
        self.collectionTapAction(indexPath);
    }
}

- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat width = (SCREEN_WIDTH - 6) / 3.;
    return CGSizeMake(width, width + 2);
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
